const path = require('path');
const HTMLWebpackPlugin = require('html-webpack-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
console.log(__dirname);
module.exports = {
    entry: path.join(__dirname, './src/index.ts'),
    output: {
        path: path.resolve(__dirname, './dist'),
        filename: 'main.js',
        environment: {
            arrowFunction: false,
            const: false,
        },
    },
    resolve: {
        extensions: ['.js', '.ts', '.tsx'],
    },
    module: {
        rules: [
            {
                test: /\.ts$/,
                use: ['babel-loader', 'ts-loader'],
                exclude: /node_modules/,
            },
            {
                test: /\.(css|less)$/,
                // test: /\.less$/,
                use: [
                    'style-loader',
                    'css-loader',
                    {
                        loader: 'postcss-loader',
                        options: {
                            postcssOptions: {
                                plugins: [
                                    [
                                        'postcss-preset-env',
                                        {
                                            browsers: 'last 2 versions',
                                        },
                                    ],
                                ],
                            },
                        },
                    },
                    'less-loader',
                ],
            },
        ],
    },
    devtool: process.env.NODE_END === 'production' ? false : 'inline-source-map',
    devServer: {
        // contentBase: path.join(__dirname, '../dist'),
        static: {
            directory: path.join(__dirname, 'public'),
        },
        compress: false,
        host: 'localhost',
        port: 3000,
    },
    plugins: [
        new CleanWebpackPlugin({
            CleanOnceBeforeBuildPatterns: [path.join(__dirname, './dist')],
        }),
        new HTMLWebpackPlugin({
            template: './src/index.html',
        }),
    ],
};
